# Maintainer: nalla <nalla@hamal.uberspace.de>

pkgname=('git-extra')
_ver_base=1.1
pkgver=1.1.157.a861f7b
pkgrel=1
pkgdesc="Git for Windows extra files"
arch=('i686' 'x86_64')
url="https://github.com/git-for-windows/build-extra"
license=('GPL')
groups=('VCS')
depends=('git-for-windows-keyring')
optdepends=('vim' 'filesystem')
install='git-extra.install'
pkgver() {
  cd "$startdir"
  rev="$(git rev-list -1 HEAD -- .)"
  test -n "$(git show . |
    sed -n -e '1,/^@@/d' -e '/^[-+]pkgver=/d' -e '/^[-+]/p')" ||
  rev="$(git rev-list -1 $rev^ -- .)"
  printf "%s.%s.%s" "${_ver_base}" "$(git rev-list --count $rev -- .)" \
    "$(git rev-parse --short $rev)"
}
source=('inputrc'
        'vimrc'
        'vi'
        'notepad'
        'wordpad'
        'create-shortcut.c'
        'Makefile'
        'SystemInfo.cpp'
        'SystemInfo.h'
        'WhoUses.cpp'
        'git-prompt.sh'
        'aliases.sh'
        'env.sh'
        'bash_profile.sh'
        'msys2-32.ico'
        '99-post-install-cleanup.post'
        'gitattributes'
        'astextplain'
        'git-sdk.sh'
        'git-update')
md5sums=('3fab57079f0322efe256e95fe29d516f'
         'a2d3b63eb1c88c2a2b011ccf0b219d60'
         'bfb591886b2a28af3334521e71198b74'
         '11d0e9aad647db83c56d9a89608baf11'
         'e3b411a4f2e6553e41d0c4261160dd7d'
         'fb92ea53ef01b4f60ed04eabac81e2c7'
         '7180794bfa88c1f687c1a7940fc62293'
         'f0098a4ae414c44f336e52ae5fc17bce'
         '5ab834ba300fabf88ca8c4d0d8569b8d'
         'eb10eb010f37dfa74af52ae6d342315b'
         'babde8f3bd9ae28b29c0866772cbb65e'
         '97dfb0ef144c605dc6bb16fbac382f9a'
         '3f3dff320418411107e3111be9d4b256'
         'f86996ac59f25aff763a81695bbd8696'
         'a8feb7ee2fa91bb179478f099444746f'
         'bdeb6046510aa1a6cd76e7f86673aa3f'
         '52c242d0c84d6934ec6a94766f8a70f0'
         'e87a5075629b58fe329094b92c1d13db'
         '593dbce30c442529b4351650f4422b6e'
         'da5db7644f0aff6567185a5495435415')

prepare() {
  test $startdir/$pkgname.install -nt $startdir/$pkgname.install.in &&
  test $startdir/$pkgname.install -nt $startdir/gitconfig &&
  test $startdir/$pkgname.install -nt $startdir/gitattributes ||
  sed -e "/^@@GITCONFIG@@$/r $startdir/gitconfig" \
	-e "/^@@GITCONFIG@@$/d" \
	-e "/^@@GITATTRIBUTES@@$/r $startdir/gitattributes" \
	-e "/^@@GITATTRIBUTES@@$/d" \
	<$startdir/$pkgname.install.in >$startdir/$pkgname.install
}

build() {
  export CC=${MINGW_CHOST}-gcc
  export CXX=${MINGW_CHOST}-g++
  export SRCDIR=$srcdir
  export BUILDDIR=build-${MINGW_CHOST}
  mkdir -p ${BUILDDIR}
  make -f Makefile
}

package() {
  builddir=build-${MINGW_CHOST}
  install -d -m755 $pkgdir/etc/profile.d
  install -d -m755 $pkgdir/etc/post-install
  install -d -m755 $pkgdir/usr/bin
  install -d -m755 $pkgdir/usr/share/git
  install -d -m755 $pkgdir/${MINGW_PREFIX}/bin
  install -m644 inputrc $pkgdir/etc
  install -m644 vimrc $pkgdir/etc
  install -m755 vi $pkgdir/usr/bin
  install -m755 notepad $pkgdir/usr/bin
  install -m755 wordpad $pkgdir/usr/bin
  install -m755 $builddir/create-shortcut.exe $pkgdir/${MINGW_PREFIX}/bin
  install -m755 $builddir/WhoUses.exe $pkgdir/${MINGW_PREFIX}/bin
  install -m755 git-prompt.sh $pkgdir/etc/profile.d
  install -m755 aliases.sh $pkgdir/etc/profile.d
  install -m755 env.sh $pkgdir/etc/profile.d
  install -m755 bash_profile.sh $pkgdir/etc/profile.d
  install -m755 git-sdk.sh $pkgdir/etc/profile.d
  install -m644 msys2-32.ico $pkgdir/usr/share/git
  install -m644 99-post-install-cleanup.post $pkgdir/etc/post-install
  install -m755 astextplain $pkgdir/usr/bin
  install -m755 git-update $pkgdir/${MINGW_PREFIX}/libexec/git-core
}
